package com.example.spring_blog_24_9_8.model;

import com.example.spring_blog_24_9_8.constants.Constant;
import lombok.Data;

@Data
public class Result {
    private int code;
    private String msg;
    private Object data;

    /**
     * 业务成功时执行的方法
     */
    public static Result success(Object data){
        Result result = new Result();
        result.setCode(Constant.SUCCESS_CODE);
        result.setMsg("");
        result.setData(data);
        return result;
    }

    /**
     *  业务执⾏失败时返回的⽅法
     */
    public  static  Result fail(int code, String msg){
        Result result = new Result();
        result.setCode(Constant.FAIL_CODE);
        result.setMsg(msg);
        result.setData("");
        return result;
    }

    /**
     * ⽤⼾未登录时返回的⽅法
     */
    public static Result unlogin(int code,String msg,Object data){
        Result result = new Result();
        result.setCode(Constant.UNLOGIN_CODE);
        result.setMsg("用户未登录");
        result.setData(data);
        return result;
    }
}
